﻿namespace TestServices
{
    using System;

    public class DialogBrain
    {
        private readonly IServiceProvider serviceProvider;

        public DialogBrain(IServiceProvider serviceProvider)
        {
            // <pex>
            if (serviceProvider == (IServiceProvider)null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            // </pex>
            this.serviceProvider = serviceProvider;
        }

        public string GetResult(string xInp, string yInp)
        {
            string ret = "";
            ICalc calc = (ICalc) serviceProvider.GetService(typeof (ICalc));
            IConvertor convertor = (IConvertor) serviceProvider.GetService(typeof (IConvertor));
            
            int x = convertor.TextToInt(xInp);
            int y = convertor.TextToInt(yInp);
            int z = calc.Add(x, y);
            ret = convertor.IntToText(z);

            return ret;
        }
    }
}